#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence
@file: app_conf.py
@time: 2017/12/27 21:46
"""

# 列表页抓取失败
SEARCH_LIST_FAIL = 0
# 搜索成功
SEARCH_LIST_SUCCESS = 1
# 没有搜索到相关信息
SEARCH_LIST_NOT_FOUND = 2
# 匹配到曾用名
SEARCH_LIST_HISTORY_NAME_FOUND = 3

# 抓取失败
CRAWL_DETAIL_FAIL = 0
# 抓取成功
CRAWL_DETAIL_SUCCESS = 1
# 抓取部分成功
CRAWL_DETAIL_PART_SUCCESS = 2

# 省份信息
PROVINCE_LIST = [
    'gansu',
    'gsxt',
    'hunan',
    'beijing',
    'tianjin',
    'hebei',
    'shandong',
    'guangxi',
    'qinghai',
    'jiangsu',
    'ningxia',
    'sichuan',
    'liaoning',
    'guangdong',
    'jilin',
    'shanxi',
    'anhui',
    'shanghai',
    'xizang',
    'hainan',
    'shanxicu',
    'neimenggu',
    'yunnan',
    'hubei',
    'zhejiang',
    'heilongjiang',
    'chongqing',
    'xinjiang',
    'henan',
    'guizhou',
    'fujian',
    'jiangxi',
]

# 省份代码
PROVINCE_CODE_DICT = {
    # 甘肃
    'gansu': 620000,
    # 总局
    'gsxt': '',
    # 湖南
    'hunan': 430000,
    # 北京
    'beijing': 110000,
    # 天津
    'tianjin': 120000,
    # 河北
    'hebei': 130000,
    'shandong': 370000,
    'guangxi': 450000,
    'qinghai': 630000,
    'jiangsu': 320000,
    'ningxia': 640000,
    'sichuan': 510000,
    'liaoning': 210000,
    'guangdong': 440000,
    'jilin': 220000,
    'shanxi': 610000,
    'anhui': 340000,
    'shanghai': 310000,
    'xizang': 540000,
    'hainan': 460000,
    'shanxicu': 140000,
    'neimenggu': 150000,
    'yunnan': 530000,
    'hubei': 420000,
    'zhejiang': 330000,
    'heilongjiang': 230000,
    'chongqing': 500000,
    'xinjiang': 650000,
    'henan': 410000,
    'guizhou': 520000,
    'fujian': 350000,
    'jiangxi': 360000,
}

PROVINCE_HOST_DICT = {
    # 甘肃
    'gansu': 'gs.gsxt.gov.cn',
    # 总局
    'gsxt': 'www.gsxt.gov.cn',
    # 湖南
    'hunan': 'hn.gsxt.gov.cn',
    # 北京
    'beijing': 'bj.gsxt.gov.cn',
    # 天津
    'tianjin': 'tj.gsxt.gov.cn',
    # 河北
    'hebei': 'he.gsxt.gov.cn',
    'shandong': 'sd.gsxt.gov.cn',
    'guangxi': 'gx.gsxt.gov.cn',
    'qinghai': 'qh.gsxt.gov.cn',
    'jiangsu': 'js.gsxt.gov.cn',
    'ningxia': 'nx.gsxt.gov.cn',
    'sichuan': 'sc.gsxt.gov.cn',
    'liaoning': 'ln.gsxt.gov.cn',
    'guangdong': 'gd.gsxt.gov.cn',
    'jilin': 'jl.gsxt.gov.cn',
    'shanxi': 'sn.gsxt.gov.cn',
    'anhui': 'ah.gsxt.gov.cn',
    'shanghai': 'sh.gsxt.gov.cn',
    'xizang': 'xz.gsxt.gov.cn',
    'hainan': 'hi.gsxt.gov.cn',
    'shanxicu': 'sx.gsxt.gov.cn',
    'neimenggu': 'nm.gsxt.gov.cn',
    'yunnan': 'yn.gsxt.gov.cn',
    'hubei': 'hb.gsxt.gov.cn',
    'zhejiang': 'zj.gsxt.gov.cn',
    'heilongjiang': 'hl.gsxt.gov.cn',
    'chongqing': 'cq.gsxt.gov.cn',
    'xinjiang': 'xj.gsxt.gov.cn',
    'henan': 'ha.gsxt.gov.cn',
    'guizhou': 'gz.gsxt.gov.cn',
    'fujian': 'fj.gsxt.gov.cn',
    'jiangxi': 'jx.gsxt.gov.cn',
}

# # 省份信息
# PROVINCE_LIST = [
#     'gansu',
#     'gsxt',
#     'hunan',
# ]
#
# # 省份代码
# PROVINCE_CODE_DICT = {
#     # 甘肃
#     'gansu': 620000,
#     # 总局
#     'gsxt': '',
#     # 湖南
#     'hunan': 430000,
# }
#
# PROVINCE_HOST_DICT = {
#     # 甘肃
#     'gansu': 'gs.gsxt.gov.cn',
#     # 总局
#     'gsxt': 'www.gsxt.gov.cn',
#     # 湖南
#     'hunan': 'hn.gsxt.gov.cn',
#
# }

# # 种子表列表 与搜索省份关联
# SEED_TABLE_LIST = {
#     'gsxt': 'new_gsxt_company_list',
# }

PROVINCE_REGISTER_CODE = {
    '11': 'beijing',
    '37': 'shandong',
    '43': 'hunan',
    '45': 'guangxi',
    '63': 'qinghai',
    '32': 'jiangsu',
    '64': 'ningxia',
    '51': 'sichuan',
    '21': 'liaoning',
    '44': 'guangdong',
    '22': 'jilin',
    '61': 'shanxi',
    '34': 'anhui',
    '12': 'tianjin',
    '31': 'shanghai',
    '54': 'xizang',
    '62': 'gansu',
    '13': 'hebei',
    '46': 'hainan',
    '14': 'shanxicu',
    '15': 'neimenggu',
    '53': 'yunnan',
    '42': 'hubei',
    '33': 'zhejiang',
    '23': 'heilongjiang',
    '50': 'chongqing',
    '65': 'xinjiang',
    '41': 'henan',
    '52': 'guizhou',
    '35': 'fujian',
    '36': 'jiangxi',
}

CRAWL_TABLE_CONF = {

    # 企业种子表
    'seed_table': {
        # 抓取列表页成功且抓取详情页成功
        'detail_select_param': {'$and': [{'crawl_status': {'$ne': CRAWL_DETAIL_SUCCESS}},
                                         {'search_status': {'$ne': SEARCH_LIST_NOT_FOUND}}]},

        # 只抓取列表页
        'list_select_param': {'$or': [{'search_status': None},
                                      {'search_status': SEARCH_LIST_FAIL}]},

        'crawl_flag': 'crawl_status',
        'search_flag': 'search_status',
    },

    # 详情页参数表 表名称与省份信息关联 比如: new_gansu_search_list
    # 'param_table': {
    #     'table': 'new_gsxt_search_list',
    # },
    #
    # # 列表页结果存储 表名称与省份信息关联 比如: new_gansu_search_page
    # 'list_page_table': {
    #     'table': 'new_gsxt_search_page',
    # },

    # 结果存储 分省份存储，方便后期快速解析局部省份信息 表名称与省份信息关联 比如: new_gansu_web_page
    'result_table': {
        # 'table': 'new_gsxt_web_page',
        'parse_flag': 'parse_status',
    },
}

# js 解密服务
JS_DECODE_URL = 'http://cs5:3005/gsxt'

# 浙江加密服务
ENCRY_ZJ_URL = 'http://cs4:4000/api/run_script/gs_zj'
